{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "f1c37d3e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import configparser\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4679387b",
   "metadata": {},
   "outputs": [],
   "source": [
    "conf = configparser.ConfigParser()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "01149a28",
   "metadata": {},
   "outputs": [],
   "source": [
    "conf['key_config'] = {'name':'cj','age':1111}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "77fba7df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<configparser.ConfigParser at 0x2b74ed5c880>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "conf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "61a68c51",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('config_test.ini', 'w') as config:\n",
    "    conf.write(config)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c8cc5842",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "cdf2259b",
   "metadata": {},
   "outputs": [],
   "source": [
    "os.startfile(os.path.abspath(''))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "acd9a676",
   "metadata": {},
   "outputs": [],
   "source": [
    "conf['keys_config1'] = {'name':'cj','age':2222}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "3022f71e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['config_test.ini']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "conf.read('config_test.ini')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "f9f28010",
   "metadata": {},
   "outputs": [],
   "source": [
    "list_conf = conf.sections()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "ebf44612",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['key_config', 'keys_config1']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list_conf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "e47bead3",
   "metadata": {},
   "outputs": [],
   "source": [
    "keys = conf['key_config']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "ceab85cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Section: key_config>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "keys"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "a2c4ec3d",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = dict(keys)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "68589576",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'cj', 'age': '1111'}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a8d55559",
   "metadata": {},
   "outputs": [],
   "source": [
    "conf = configparser.ConfigParser()  #实例化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "0ae526a8",
   "metadata": {},
   "outputs": [],
   "source": [
    "conf['test'] = {'name':'cc','name1':'jj'}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "bbaff471",
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('config.ini', 'w', encoding='utf8') as a:\n",
    "    conf.write(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "6e8e0414",
   "metadata": {},
   "outputs": [],
   "source": [
    "path = os.startfile(os.path.join(os.path.abspath(''),'config.ini'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "97bcfa70",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['config.ini']"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "conf.read('config.ini')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "e03ae3c3",
   "metadata": {},
   "outputs": [],
   "source": [
    "list_con = conf.sections()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "c68fe7cb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['test']"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list_con"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "18ed7a06",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "b175a122",
   "metadata": {},
   "outputs": [],
   "source": [
    "sec = conf['test']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "df5d30f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Section: test>"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sec"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "48ef64f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = dict(sec)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "57af7e55",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'cc', 'name1': 'jj'}"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d76681a",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
